import {
	reactive
} from "vue";
import {
	getSign
} from "@/config/api/wxConfig";
import config from '@/config/common';
const useWxConfig = () => {
	// 配置
	const wxConfig = reactive({
		debug: false,
		appId: config.appid, // 必填，公众号的唯一标识
		timestamp: '', // 必填，生成签名的时间戳
		nonceStr: '', // 必填，生成签名的随机串
		signature: '', // 必填，签名
		jsApiList: ['scanQRCode', 'openAddress', 'getLocation', 'chooseWXPay'] // 必填，需要使用的JS接口列表
	});
	//获取签名
	const getSignature = async () => {
		try {
			const url = window.location.href.split('#')[0];
			const {
				data
			} = await getSign(url);
			wxConfig.timestamp = data.timestamp;
			wxConfig.nonceStr = data.noncestr;
			wxConfig.signature = data.signature;
			jWeixin.config(wxConfig);
			jWeixin.ready(() => {
				console.log("wxconfig Success");
			});
			jWeixin.error(() => {
				console.log("wxconfig error");
			})
		} catch (e) {
			//TODO handle the exception
		}

	}
	return {
		getSignature
	}
}
export default useWxConfig;